package com.atguigu.realtime.app.function;

import com.atguigu.realtime.common.GmallConstant;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

/**
 * @ClassName: KeyWordProductUDTF
 * @Description:
 * @Author: kele
 * @Date: 2021/4/28 9:50
 **/
@FunctionHint(output = @DataTypeHint("ROW<source STRING,ct BIGINT>"))
public class KeyWordProductUDTF  extends TableFunction<Row> {

    //注意：传参的数据类型必须是 封装类型的数据，否则不支持
    public void eval(Long click_ct,Long cart_ct,Long order_ct) {

        if(click_ct > 0){
            collect(Row.of(GmallConstant.KEYWORD_CLICK,click_ct));
        }

        if(cart_ct > 0){
            collect(Row.of(GmallConstant.KEYWORD_CART,cart_ct));
        }

        if(order_ct > 0){
            collect(Row.of(GmallConstant.KEYWORD_ORDER,order_ct));
        }

    }

}
